package de.haw.HESextern.Transport.webService;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import com.sun.xml.internal.ws.developer.UsesJAXBContext;

import de.haw.HESextern.Transport.TransportComplex;
import de.haw.HESextern.Transport.TransportId;
import de.haw.HESextern.Transport.TransportTabCache;
import de.haw.HESextern.Transport.TransportTabCacheMock;

@Path("/TransportExtern")
public class TransportServiceExternWeb {
	
	private TransportTabCache cache;

	public TransportTabCache getCache() {
		if(cache==null) {
			cache = new TransportTabCacheMock();
		}
		return cache;
	}

	@GET
	@Produces("application/json")
	public Response getDeliveryStatus(@QueryParam("id") String id) {
		if(id == null) 
			id="1";
		TransportId idTransport = new TransportId(Integer.parseInt(id));
		TransportComplex transportById = getCache().getTransportById(idTransport);
		if(transportById == null) {
			return Response.status(Response.Status.NOT_FOUND).build();
		}
		return Response.ok(transportById).build();
	}
	
}
